import Router from "koa-router";
import {Op} from "sequelize";
import createModel from "./testModel.js";


const router = Router({
  prefix: '/sqlServer'
})

router.post('/get', async (ctx, next) => {
  // let res = await sqlServerSql.query('SELECT top 1 * FROM SYS_User', {type: QueryTypes.SELECT});
  let tableName = ['Air_h_2024_1009A_App', 'Air_h_2024_1010A_App', 'Air_h_2024_1011A_App'];
  let resAll = [];
  for (let i = 0; i < tableName.length; i++) {
    let sql = `SELECT top 1 * FROM ${tableName[i]}`;
    const dataModel = createModel(tableName[i]);

    let res = await dataModel.findAndCountAll({
      where: {
        id: {
          [Op.lt]: 1000,
        }
      },
      offset: 1000,
      limit: 2
    });
    resAll = resAll.concat(res);
  }
  ctx.body = resAll;
})

export default router;